
// ## 2023/06/22 # 黑店小小二 # 太守自治UI ##

/*
征兵 开关 治安 资金 兵粮比
训练 开关 士气
巡查 开关 治安
褒奖 开关 忠诚
运输 开关 

模式选择
一：巡察-训练-征兵-褒奖-运输
二：巡察-征兵-训练-褒奖-运输
三：征兵-巡察-训练-褒奖-运输
四：征兵-训练-巡察-褒奖-运输
五：训练-征兵-巡察-褒奖-运输
六：训练-巡察-征兵-褒奖-运输
 */

namespace taishu_autonomy_UI
{
  const int 内政自动化_征兵 = 0;
  const int 内政自动化_训练 = 1;
	const int 内政自动化_巡察 = 2;
	const int 内政自动化_褒赏 = 3;
	const int 内政自动化_运输 = 4;

	class Main {
		pk::dialog@ taishu_autonomy_dialog;
    pk::dialog@ model_dialog;
    array<array<pk::widget@>> widget_list(5, array<pk::widget@>(5));
		array<pk::button@> mode_select_btns(6, null);
		array<pk::sprite9@> mode_select_bg(6, null);
		array<pk::text@> mode_select_text(6, null);
		array<array<pk::button@>> button_list(5, array<pk::button@>(4));
    pk::text@ content_text;
		array<string> type_list = { '征 兵', '训 练', '巡 查', '褒 奖', '运 输' };
		array<array<string>> action_list = { 
			{'开关', '治安', '资金', '兵粮比'},
			{'开关', '士气'},
			{'开关', '治安'},
			{'开关', '忠诚'},
			{'开关'}
		};
		array<string> mode_list = {
			'巡察-训练-征兵-褒奖-运输',
			'巡察-征兵-训练-褒奖-运输',
			'征兵-巡察-训练-褒奖-运输',
			'征兵-训练-巡察-褒奖-运输',
			'训练-征兵-巡察-褒奖-运输',
			'训练-巡察-征兵-褒奖-运输'
		};
		array<array<int>> data = {
			/*征兵*/ { /*开关*/0, /*治安*/0, /*资金*/0, /*兵粮比*/0 },
			/*训练*/ { /*开关*/0, /*士气*/0 },
			/*巡查*/ { /*开关*/0, /*治安*/0 },
			/*褒奖*/ { /*开关*/0, /*忠诚*/0 },
			/*运输*/ { /*开关*/0 }
		};
    array<array<string>> content_data = {
      { "玩家结束回合，若满足征兵条件，则会\x1b[01x自动执行征兵\x1b[0x", "功能开关。\n关闭时后面配置无效。", "执行征兵时的\x1b[01x治安下限\x1b[0x\n即城池治安小于设定的治安时则不会征兵。", "执行征兵时的\x1b[01x金钱下限\x1b[0x\n即城池金钱小于设定的金钱时则不会征兵。", "执行征兵时的\x1b[01x金钱下限\x1b[0x\n即（城池粮食/城市兵力）小于设定的兵粮比时则不会征兵。" },
      { "玩家结束回合，若满足训练条件，则会\x1b[01x自动执行训练\x1b[0x", "功能开关。\n关闭时后面配置无效。", "执行训练时的\x1b[01x气力上限\x1b[0x\n即城池气力大于设定的气力时则不会训练。"},
      { "玩家结束回合，若满足巡查条件，则会\x1b[01x自动执行巡查\x1b[0x", "功能开关。\n关闭时后面配置无效。", "执行巡查时的\x1b[01x治安上限\x1b[0x\n即城池治安大于设定的治安时则不会巡查。"},
      { "玩家结束回合，若满足巡查条件，则会\x1b[01x自动执行褒奖\x1b[0x", "功能开关。\n关闭时后面配置无效。", "执行褒奖时的\x1b[01x忠诚上限\x1b[0x\n即武将忠诚大于设定的忠诚时则不会褒奖。"},
      { "玩家结束回合，若满足运输条件，则会\x1b[01x自动执行运输\x1b[0x", "功能开关。"},
    };
		int mode_select = 0; // 已选择模式

		pk::force @force_;
    pk::person @kunshu_;
    pk::city @city_;
    pk::building @building_;

    int menu_city_id_;
    int menu_force_id_;

    int line_height = 8;
    int item_width = 156;

		Main()
		{
			// ch::set_auto_affairs(false); // 开发期间强制关闭
			add_menu_城市内政自动化();
			pk::bind(102, pk::trigger102_t(onGameInit));
		}

		void onGameInit()
    {
      // create_taishu_autonomy_dialog();
    }

    void create_taishu_autonomy_dialog()
    {


    }

    void add_menu_城市内政自动化()
		{
			if (ch::get_auto_affairs_status()) return;
			pk::menu_item 内政自动化;
			内政自动化.menu = auto_IA_menu::菜单_自动内政;
			内政自动化.shortcut = 'Z';
			内政自动化.init = pk::building_menu_item_init_t(init);
			内政自动化.get_image_id = pk::menu_item_get_image_id_t(getImageID_1249);
			内政自动化.is_visible = pk::menu_item_is_visible_t(isVisible);
			内政自动化.get_text = cast<pk::menu_item_get_text_t@>(function() { return pk::encode("太守自治设置"); });
			内政自动化.get_desc = cast<pk::menu_item_get_desc_t@>(function() { return pk::encode("设置太守自治参数"); });
			内政自动化.handler = pk::menu_item_handler_t(handler_太守自治设置);
			pk::add_menu_item(内政自动化);
		}

		void init(pk::building @building)
    {
      @building_ = @building;
      menu_city_id_ = building_.get_id();
      menu_force_id_ = building.get_force_id();
      @force_ = pk::get_force(menu_force_id_);
      @kunshu_ = pk::get_person(force_.kunshu);
    }

    int getImageID_1249()
    {
      return 1249;
    }

    bool isVisible()
    {
      if (ch::get_auto_affairs_status()) return false;
			if (building_.get_id() >= 据点_末) return false;
			if (!pk::is_player_controlled(pk::get_city(menu_city_id_))) return false;	// 플레이어 위임군단 도시인 경우 제외

			return menu_city_id_ != -1 and menu_force_id_ == pk::get_current_turn_force_id();
    }

    bool handler_太守自治设置()
    {
      auto base_p = ch::get_base_p(menu_city_id_);
      // 征兵
      data[0] = { base_p.can_recruit ? 1 : 0, base_p.recruit_std_porder, base_p.recruit_std_gold, base_p.recruit_std_foodtroop };
      // 训练
      data[1] = { base_p.can_drill ? 1 : 0, base_p.drill_std };
      // 巡查
      data[2] = { base_p.can_inspections ? 1 : 0, base_p.inspections_std };
      // 褒奖
      data[3] = { base_p.can_reward ? 1 : 0, base_p.reward_std };
      // 运输
      data[4] = { base_p.can_transport ? 1 : 0 };

      mode_select = base_p.auto_sequence - 1;
      pk::dialog@ dialog = create_dlg();
      open_dlg(dialog);
      // update_select_mode();
      // create_city_setting(taishu_autonomy_dialog, menu_city_id_);
      return true;
    }

    string numberpad_t(int line, int original_value, int current_value)
		{
			return pk::encode("");
		}

    void open_dlg(pk::dialog@ dialog)
    {
      dialog.open();
      dialog.delete();
    }

    pk::dialog@ create_dlg()
    {
        ///////////////////背景窗体///////////////////
        pk::dialog@ dialog = pk::new_dialog();

        pk::size dialog_size = pk::size(1100, 650);
        auto buttons = UI::create_dlg_320(dialog, dialog_size, pk::encode("太守自治"));
        pk::button@ ok_button = buttons[0];
        pk::button@ esc_button = buttons[1];

        @taishu_autonomy_dialog = @dialog;
        dialog.set_pos(pk::get_resolution().width / 2 - dialog_size.width / 2, pk::get_resolution().height / 2 - dialog_size.height / 2 - 60);
        //dialog.set_size(dialog_size);
        pk::detail::funcref func0 = cast<pk::button_on_released_t@>(function(button) {
            //应用修改不需要设定，返回需要设定回原值
            main.confirm_data(main.menu_city_id_);
            main.taishu_autonomy_dialog.close(1);
        });
        ok_button.on_button_released(func0);

        func0 = cast<pk::button_on_released_t@>(function(button) {
            //应用修改不需要设定，返回需要设定回原值
            main.taishu_autonomy_dialog.close(1);
        });
        esc_button.on_button_released(func0);

        pk::button@ change_button = dialog.create_button(238);
        change_button.set_pos(964, 700);
        change_button.set_size(136, 44);
        change_button.set_text(pk::encode("开启自动内政"));

        func0 = cast<pk::button_on_released_t@>(function(button) {
            main.open_auto();
        });
        change_button.on_button_released(func0);

        pk::dialog@ dialog0 = dialog.create_dialog(false);
        pk::size dialog_size0 = pk::size(300, 350);//y331-68
        dialog0.set_pos(785, 70);
        dialog0.set_size(dialog_size0);
        init_dlg_content_arr(dialog0);

        pk::dialog@ dialog1 = dialog.create_dialog(false);
        pk::size dialog_size1 = pk::size(775, 320);//y331-68
        dialog1.set_pos(30, 40);
        dialog1.set_size(dialog_size1);
        init_dlg_from_arr(dialog1);

        @ model_dialog = dialog.create_dialog(false);
        pk::size dialog_size2 = pk::size(775, 300);//y331-68
        model_dialog.set_pos(30, 400);
        model_dialog.set_size(dialog_size2);
        init_dlg_select_arr(model_dialog);

        return dialog;
    }

    pk::dialog@ init_dlg_from_arr(pk::dialog@ new_dialog)
    {
      pk::sprite9@ bg0;
      pk::button@ bt0;
      pk::text@ tx0;

      pk::detail::funcref func00 = cast<pk::widget_on_hover_enter_t@>(function(self, widget) {
        for (int i = 0; i < int(main.widget_list.length); i += 1)
        {
          for (int a = 0; a < int(main.widget_list[i].length); a += 1)
          {
            if (main.widget_list[i][a] !is null and widget.get_id() == main.widget_list[i][a].get_id())
            {
              main.content_text.set_text(pk::text_wrap(pk::encode(main.content_data[i][a]), 34, 9));
            }
          }
        }
        for (int i = 0; i < int(main.button_list.length); i += 1)
        {
          for (int a = 0; a < int(main.button_list[i].length); a += 1)
          {
            if (main.button_list[i][a] !is null and widget.get_id() == main.button_list[i][a].get_id())
            {
              main.content_text.set_text(pk::text_wrap(pk::encode(main.content_data[i][a + 1]), 34, 9));
            }
          }
        }
      });
      pk::detail::funcref func01 = cast<pk::widget_on_hover_leave_t@>(function(self, widget) { 
        main.content_text.set_text("");
      });
      new_dialog.on_widget_hover_enter(func00);
      new_dialog.on_widget_hover_leave(func01);

      for (int i = 0; i < 5; i += 1)
      {
        int y = 30 + 60 * i;
        @ bg0 = new_dialog.create_sprite9(384);
        bg0.set_pos(0, y);
        bg0.set_size(80, 40);

        @ tx0 = new_dialog.create_text();
        tx0.set_pos(0, y);
        tx0.set_size(80, 40);
        tx0.set_text(pk::encode(type_list[i]));
        tx0.set_text_font(FONT_BIG);
        tx0.set_text_align(0x4|0x20);

        @widget_list[i][0] = @ bg0;

        // action_list
        for (int a = 0; a < int(action_list[i].length); a += 1)
        {
          int x = 160 * a + 100;
          @ bg0 = new_dialog.create_sprite9(393);
          bg0.set_pos(x, y);
          bg0.set_size(145, 40);
          @ tx0 = new_dialog.create_text();
          tx0.set_pos(x, y);
          tx0.set_size(60, 40);
          tx0.set_text(pk::encode(action_list[i][a]));
          tx0.set_text_align(0x4|0x20);

          @widget_list[i][a + 1] = @ bg0;

          string btn_text = '';
          if (a == 0) btn_text = data[i][a] == 0 ? '关闭' : '开启';
          else btn_text = formatInt(data[i][a]);

          @ bt0 = new_dialog.create_button(1526);
          bt0.set_pos(x + 60, y + 5);  // y: 100 + 134 + 10; x: 26 + 10
          bt0.set_size(75, 30);
          bt0.set_text(pk::encode(btn_text));
          bt0.set_text_align(0x4|0x20);

          @button_list[i][a] = @bt0;

          pk::detail::funcref func0;
          pk::detail::funcref func1;
          pk::detail::funcref func2;
          pk::detail::funcref func3;
          pk::detail::funcref func4;

          if (a == 0)
          {
            func0 = cast<pk::button_on_pressed_t@>(function(button) {
              main.toggle_params(main.menu_force_id_, main.menu_city_id_, 内政自动化_征兵, 0);
              main.updateShowData();
            });
            func1 = cast<pk::button_on_pressed_t@>(function(button) {
              main.toggle_params(main.menu_force_id_, main.menu_city_id_, 内政自动化_训练, 0);
              main.updateShowData();
            });
            func2 = cast<pk::button_on_pressed_t@>(function(button) {
              main.toggle_params(main.menu_force_id_, main.menu_city_id_, 内政自动化_巡察, 0);
              main.updateShowData();
            });
            func3= cast<pk::button_on_pressed_t@>(function(button) {
              main.toggle_params(main.menu_force_id_, main.menu_city_id_, 内政自动化_褒赏, 0);
              main.updateShowData();
            });
            func4 = cast<pk::button_on_pressed_t@>(function(button) {
              main.toggle_params(main.menu_force_id_, main.menu_city_id_, 内政自动化_运输, 0);
              main.updateShowData();
            });
          }

          if (a == 1)
          {
            func0 = cast<pk::button_on_pressed_t@>(function(button) {
              main.toggle_params(main.menu_force_id_, main.menu_city_id_, 内政自动化_征兵);
              main.updateShowData();
            });
            func1 = cast<pk::button_on_pressed_t@>(function(button) {
              main.toggle_params(main.menu_force_id_, main.menu_city_id_, 内政自动化_训练);
              main.updateShowData();
            });
            func2 = cast<pk::button_on_pressed_t@>(function(button) {
              main.toggle_params(main.menu_force_id_, main.menu_city_id_, 内政自动化_巡察);
              main.updateShowData();
            });
            func3= cast<pk::button_on_pressed_t@>(function(button) {
              main.toggle_params(main.menu_force_id_, main.menu_city_id_, 内政自动化_褒赏);
              main.updateShowData();
            });
          }
          if (a == 2)
          {
            func0 = cast<pk::button_on_pressed_t@>(function(button) {
              main.toggle_params(main.menu_force_id_, main.menu_city_id_, 内政自动化_征兵, 2);
              main.updateShowData();
            });
          }
          if (a == 3)
          {
            func0 = cast<pk::button_on_pressed_t@>(function(button) {
              main.toggle_params(main.menu_force_id_, main.menu_city_id_, 内政自动化_征兵, 3);
              main.updateShowData();
            });
          }

          switch (i)
          {
            case 0:
              bt0.on_button_pressed(func0);
              break;
            case 1:
              bt0.on_button_pressed(func1);
              break;
            case 2:
              bt0.on_button_pressed(func2);
              break;
            case 3:
              bt0.on_button_pressed(func3);
              break;
            case 4:
              bt0.on_button_pressed(func4);
              break;
          }
        }
      }

      return new_dialog;
    }

    pk::dialog@ init_dlg_content_arr(pk::dialog@ new_dialog)
    {
      pk::sprite9@ bg0;
      pk::text@ tx0;

      @ bg0 = new_dialog.create_sprite9(411);
      bg0.set_pos(0, 0);
      bg0.set_size(300, 350);

      @content_text = new_dialog.create_text();
      content_text.set_pos(10, 10);
      content_text.set_size(280, 300);
      content_text.set_text_align(TEXT_ALIGN_LEFT | TEXT_ALIGN_TOP);

      return new_dialog;
    }

    pk::dialog@ init_dlg_select_arr(pk::dialog@ new_dialog)
    {

      pk::sprite9@ bg0;
      pk::button@ bt0;
      pk::text@ tx0;

      @ bg0 = new_dialog.create_sprite9(393);
      bg0.set_pos(0, 0);
      bg0.set_size(120, 40);

      @ tx0 = new_dialog.create_text();
      tx0.set_pos(0, 0);
      tx0.set_size(120, 40);
      tx0.set_text(pk::encode('模式选择'));
      tx0.set_text_font(FONT_BIG);
      tx0.set_text_align(0x4|0x20);

      for (int i = 0; i < int(mode_list.length); i += 1)
      {
        int x = 0;
        int y = 50 + 40 * i;

        @ bt0 = new_dialog.create_button(214);
        bt0.set_pos(x, y);
        bt0.set_size(78, 30);
        bt0.set_text(pk::encode(mode_select == i ? "已选择" : "选择"));
        @mode_select_btns[i] = @bt0;

        pk::detail::funcref func0 = cast<pk::button_on_pressed_t@>(function(button) {
          main.mode_select = 0;
          main.update_select_mode();
        });
        pk::detail::funcref func1 = cast<pk::button_on_pressed_t@>(function(button) {
          main.mode_select = 1;
          main.update_select_mode();
        });
        pk::detail::funcref func2 = cast<pk::button_on_pressed_t@>(function(button) {
          main.mode_select = 2;
          main.update_select_mode();
        });
        pk::detail::funcref func3 = cast<pk::button_on_pressed_t@>(function(button) {
          main.mode_select = 3;
          main.update_select_mode();
        });
        pk::detail::funcref func4 = cast<pk::button_on_pressed_t@>(function(button) {
          main.mode_select = 4;
          main.update_select_mode();
        });
        pk::detail::funcref func5 = cast<pk::button_on_pressed_t@>(function(button) {
          main.mode_select = 5;
          main.update_select_mode();
        });
        switch (i)
        {
          case 0:
            bt0.on_button_pressed(func0);
            break;
          case 1:
            bt0.on_button_pressed(func1);
            break;
          case 2:
            bt0.on_button_pressed(func2);
            break;
          case 3:
            bt0.on_button_pressed(func3);
            break;
          case 4:
            bt0.on_button_pressed(func4);
            break;
          case 5:
            bt0.on_button_pressed(func5);
            break;
        }

        @ bg0 = new_dialog.create_sprite9(393); // true: 357 false 393
        bg0.set_pos(x + 78 + 20, y);  // y: 100 + 134 + 10; x: 26 + 10
        bg0.set_size(70, 30);

        @mode_select_bg[i] = @bg0;

        pk::text @text0 = new_dialog.create_text();
        text0.set_pos(x + 78 + 20, y);
        text0.set_size(70, 30);
        text0.set_text(pk::encode('模式' + (i + 1)));
        text0.set_text_align(0x4|0x20);
        @mode_select_text[i] = @text0;

        @text0 = new_dialog.create_text();
        text0.set_pos(x + 78 + 20 + 70 + 20 + 20, y);
        text0.set_size(250, 30);
        text0.set_text(pk::encode(mode_list[i]));
        text0.set_text_align(0x20);

      }

      return new_dialog;
    }

    void open_auto()
    {
      int choose = pk::choose({ pk::encode("  是  "), pk::encode("  否  "), pk::encode("功能介绍") }, pk::encode("（要开启自动内政功能吗？）"), kunshu_);
      if (choose == 0)
      {
        ch::set_auto_affairs(true);
        taishu_autonomy_dialog.close(1);
        pk::message_box(pk::encode("(已开启自动内政，可以在\x1b[02x自动内政窗口\x1b[0x关闭)"), kunshu_);
        
      }
      else if (choose == 2)
      {
        pk::scene(pk::scene_t(scene_自动内政教学));
        
      }
    }

    void scene_自动内政教学()
    {
      pk::person @gunshi_ = pk::is_valid_person_id(force_.gunshi) ? pk::get_person(force_.gunshi) : pk::get_person(武将_文官);
      pk::message_box(pk::encode("好的，那下面由臣来简单介绍下全新的自动内政系统吧。"), gunshi_);
      pk::message_box(pk::encode("\x1b[01x自动内政系统\x1b[0x将代替原来的\x1b[02x太守自治\x1b[0x功能，两者的区别在于，自动内政每项事务\x1b[16x只需一名专属的执政官\x1b[0x。"), gunshi_);
      pk::message_box(pk::encode("另外无论该执政官是否行动，或是出门在外(交由副手)，\x1b[01x均可产生对应内政收益\x1b[0x。"), gunshi_);
      // pk::background("mediaEX/background/autoafair/IA1.png");
      pk::message_box(pk::encode("自动内政的对应\x1b[02x信息面板\x1b[0x会\x1b[01x替换\x1b[0x原太守自治的信息面板，显示在城市信息的右侧，在此可以了解到内政操作的分配。"), gunshi_);
      pk::message_box(pk::encode("而原太守自治的\x1b[02x城市菜单\x1b[0x也会被劝降的自动内政菜单\x1b[01x替换\x1b[0x，用以完成和自动内政相关的分配工作。"), gunshi_);
      // pk::background("mediaEX/background/autoafair/IA2.png");
      pk::message_box(pk::encode("城市正上方的据点信息会\x1b[02x新增四条\x1b[0x和自动内政相关的\x1b[01x信息条目\x1b[0x。"), gunshi_);
      pk::message_box(pk::encode("同时，需要提醒主公，既然主公决定将内政事务放手给麾下的能臣，那以后也就无需过多插手内政事务的具体执行。"), gunshi_);
      // pk::background("mediaEX/background/autoafair/IA3.png");
      pk::message_box(pk::encode("所以，征兵生产巡查训练的\x1b[01x指令\x1b[0x在开启自动内政后将\x1b[29x不可使用\x1b[0x。"), gunshi_);
      pk::message_box(pk::encode("如果主公中途想亲力亲为，也可直接关闭自动内政。不过需要消耗一定的\x1b[01x技巧\x1b[0x跟\x1b[01x金钱\x1b[0x"), gunshi_);
    }

    void update_select_mode()
    {
      pk::sprite9@ bg0;
      // mode_select
      for (int i = 0; i < int(mode_list.length); i += 1)
      {
        mode_select_btns[i].set_text(pk::encode('选择'));
        model_dialog.remove_child(mode_select_bg[i].get_id());
        model_dialog.remove_child(mode_select_text[i].get_id());

        int x = 0;
        int y = 50 + 40 * i;

        @ bg0 = model_dialog.create_sprite9(mode_select == i ? 357 : 393);
        bg0.set_pos(x + 78 + 20, y);
        bg0.set_size(70, 30);
        @mode_select_bg[i] = @bg0;

        pk::text @text0 = model_dialog.create_text();
        text0.set_pos(x + 78 + 20, y);
        text0.set_size(70, 30);
        text0.set_text(pk::encode('模式' + (i + 1)));
        text0.set_text_align(0x4|0x20);
        @mode_select_text[i] = @text0;
      }

      mode_select_btns[mode_select].set_text(pk::encode('已选择'));

      auto base_p = ch::get_base_p(menu_city_id_);
      base_p.auto_sequence = uint8(mode_select + 1);
    }

    void updateShowData()
    {
      for (int i = 0; i < int(data.length); i += 1)
      {
        for (int b = 0; b < int(data[i].length); b += 1)
        {

        	string btn_text = '';
          if (b == 0) btn_text = data[i][b] == 0 ? '关闭' : '开启';
          else btn_text = formatInt(data[i][b]);
          button_list[i][b].set_text(pk::encode(btn_text));
        }
      }
    }

		void toggle_params(int force_id, int city_id, int 内政自动化_项目, int params = 1)
		{
			auto base_t = ch::get_base_p(city_id);
      if (params == 0) data[内政自动化_项目][params] = data[内政自动化_项目][params] == 0 ? 1 : 0;
      else
      {
        int max_num;
        int default_num = data[内政自动化_项目][params];
        if (params == 1)
        {
          max_num = 99;
          if (内政自动化_项目 == 内政自动化_征兵) max_num = 100;
          if (内政自动化_项目 == 内政自动化_训练) max_num = ch::get_max_energy(pk::has_tech(pk::get_force(force_id), 技巧_熟练兵));
        }
        if (params == 2) max_num = 100000; // 征兵-资金
        
        if (params == 3) max_num = 250;// 征兵-兵粮比
        pk::int_bool deal = pk::numberpad(pk::encode("内政标准"), 0, max_num, default_num, pk::numberpad_t(numberpad_t));

        if (deal.second) data[内政自动化_项目][params] = deal.first;
      }
		}

    void confirm_data (int city_id)
    {
      for (int i = 0; i < int(data.length); i += 1)
      {
        for (int a = 0; a < int(data[i].length); a += 1)
        {
          auto base_t = ch::get_base_p(city_id);
          if (a == 0)
          {
            bool result = data[i][a] == 1;
            switch (i)
            {
              case 内政自动化_征兵: base_t.can_recruit = result; break;
              case 内政自动化_训练: base_t.can_drill = result; break;
              case 内政自动化_巡察: base_t.can_inspections = result; break;
              case 内政自动化_褒赏: base_t.can_reward = result; break;
              case 内政自动化_运输: base_t.can_transport = result; break;
            }
          }
          else
          {
            int num = data[i][a];
            if (a == 1)
            {
              switch (i)
              {
                case 内政自动化_征兵: base_t.recruit_std_porder = num; break;
                case 内政自动化_训练: base_t.drill_std = num; break;
                case 内政自动化_巡察: base_t.inspections_std = num; break;
                case 内政自动化_褒赏: base_t.reward_std = num; break;
              }
            }
            else if (a == 2) base_t.recruit_std_gold = num;
            else base_t.recruit_std_foodtroop = num;
          }
        }
      }
    }
	}
	Main main;
}
